import 'dart:io';
import 'package:flutter/material.dart';

class ImageShow extends StatelessWidget {
  final String url; // http路径
  final bool isFile; // 是否为文件
  final File file; // 文件路径

  ImageShow({
    Key key,
    this.url,
    this.isFile = false,
    this.file,
  }) : super(key: key);

  Widget imageShow() {
    if (isFile) {
      return Image.file(file);
    } else {
      return FadeInImage.assetNetwork(
        placeholder: 'images/loading.gif', // 占位图
        image: url,
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: AppBar(
        backgroundColor: Colors.black,
        title: Text('图片显示'),
      ),
      body: Center(
        child: Container(
          width: double.infinity,
          height: double.infinity / 3,
          child: imageShow(),
        ),
      ),
    );
  }
}
